home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Utilitaires divers / Images / Image 1.37 ƒ / Macros / More Macros < prev    next >
Encoding:
Text File  |  1991-03-21  |  10.5 KB  |  480 lines  |  [TEXT/MSWD]

  1. macro 'Speckle Paint [S]';
  2. var
  3.   x,y,ranx,rany,MaxSpeckSize,size,Spread:integer;
  4. begin
  5.   Spread:=50;
  6.   MaxSpeckSize:=5;
  7.   KillRoi;
  8.   repeat
  9.     GetMouse(x,y);
  10.     if button then begin
  11.       ranx:=x+Spread*(Random-0.5);
  12.       rany:=y+Spread*(Random-0.5);
  13.       size:=(MaxSpeckSize-2)*random+2;
  14.       MakeOvalRoi(ranx-size,rany-size,size*2,size*2);
  15.       SetForeground(Random*254+1)
  16.       fill;
  17.     end;
  18.   until (x<0) or (y<0);
  19.   KillRoi
  20. end;
  21.  
  22.  
  23. macro 'Camera Simulator';
  24. var
  25.   left,top,width,height,n,Camera,nFrames:integer;
  26. begin
  27.   GetRoi(left,top,width,height);
  28.   if width=0 then begin
  29.     PutMessage('Please select an area of interest in the Camera window.');
  30.     exit;
  31.   end;
  32.   nFrames:=GetNumber('Number of frames:',4);
  33.   StartCapturing;
  34.   Camera:=nPics;
  35.   n:=0;
  36.   repeat
  37.     if Button then begin
  38.       MakeRoi(left,top,width,height);
  39.       n:=n+1;
  40.       Duplicate('Frame ',n:1);
  41.       SelectPic(Camera);
  42.       StartCapturing;
  43.     end;
  44.   until n=nFrames;
  45.   StopCapturing;
  46.   Dispose;
  47.   SetOption; TileWindows;
  48. end;
  49.  
  50. macro 'Draw Histogram';
  51. var
  52.   max,scale:real;
  53.   i,margin,width,height:integer;
  54. begin
  55.   Margin:=10;
  56.   width:=256;
  57.   height:=0.6*256;
  58.   Measure;
  59.   SetForegroundColor(255);
  60.   SetBackgroundColor(0);
  61.   SetLineWidth(1);
  62.   SetNewSize(width+2*margin,height+2*margin);
  63.   MakeNewWindow('Histogram');
  64.   MakeRoi(margin,margin-1,width,height+1);
  65.   DrawBoundary;
  66.   max:=0;
  67.   for i:=1 to 254 do
  68.   if histogram[i]> max then max:=histogram[i];
  69.   scale:=height/max;
  70.   for i:=1 to 254 do begin
  71.     MakeRoi(margin+i,margin,1,histogram[i]*scale);
  72.     SetForegroundColor(i);
  73.     fill;
  74.  end;
  75.   SelectAll;
  76.   FlipVertical;
  77.   KillRoi;
  78. end;
  79.  
  80.  
  81. macro 'Use Even Field';
  82. {
  83. Replaces every odd scan line with its neighboring even scan line. Can be used to improve the quality of images that have even and odd fields that are out of sync as the result of subject movement during capture. Due to a bug in PutRow(fixed in V1.34), you must force a screen update by double-click on the magnifying glass to see the result.
  84. }
  85. var
  86.   i,width,height,row:integer;
  87. begin
  88.   GetPicSize(width,height);
  89.   row:=0;
  90.   for i:=0 to height/2 do begin
  91.     GetRow(0,row,width);
  92.     PutRow(0,row+1,width);
  93.     row:=row+2;
  94.   end;
  95. end;
  96.  
  97.  
  98. macro 'Open and transfer selection [O]';
  99. begin
  100.   if nPics>0 then KillRoi; {Save Selection}
  101.   Open('');                {Prompt for file name}
  102.   RestoreROI;              {Transfer selection to new window}
  103. end;
  104.  
  105.  
  106. macro 'Subtract Background';
  107. var
  108.   i,Corrected:integer;
  109. begin
  110.   SelectAll;
  111.   Duplicate('Background Corrected');
  112.   Corrected:=PicNumber;
  113.   Duplicate('Background'); 
  114.   ScaleSelection(.25,.25);
  115.   RestoreRoi;
  116.   for i:=1 to 10 do begin
  117.     SetOption; Smooth;
  118.   end;
  119.   ScaleSelection(4,4);
  120.   SelectAll;
  121.   Copy;
  122.   SelectPic(Corrected);
  123.   Paste;
  124.   Subtract;
  125.   ResetGrayMap;
  126. end;
  127.  
  128.  
  129. macro 'ASCII Dump';
  130. {
  131. Generates an alphanumeric listing of pixels values starting at
  132. the upper left corner of the current selection. 20 rows and 44 columns
  133. can be displayed with the default 552 x 436 window. The size of the window
  134. used to display the pixel values is determined by New Width and
  135. New Height in the Prefernces dialog box.
  136. }
  137. var
  138.   image,dump,roiLeft,roiTop,roiWidth,roiHeight:integer;
  139.   h,v,value,MaxWidth,MaxHeight,width,height:integer;
  140. begin
  141.   image:=PicNumber;
  142.   GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  143.   if roiWidth=0 then begin
  144.     PutMessage('This macro requires a rectangular selection');
  145.     exit;
  146.   end;
  147.   SetForegroundColor(255);
  148.   SetBackgroundColor(0);
  149.   MakeNewWindow('ASCII Dump');
  150.   dump:=PicNumber;
  151.   GetPicSize(width,height);
  152.   MaxWidth:=width div 24 - 2;
  153.   MaxHeight:=height div 9 - 3;
  154.   if roiWidth>MaxWidth then roiWidth:=MaxWidth;
  155.   if roiHeight>MaxHeight then roiHeight:=MaxHeight;
  156.   SetFont('Monaco');
  157.   SetFontSize(9);
  158.   SetText('No background; Left Justified');
  159.   MoveTo(2,12);
  160.   write('    ');
  161.   for h:=roiLeft to roiLeft+roiWidth-1 do write(h:4);
  162.   writeln;
  163.   writeln;
  164.   for v:=roiTop to roiTop+roiHeight-1 do begin
  165.     write(v:3,' ');
  166.     for h:=roiLeft to roiLeft+roiWidth-1 do begin
  167.       ChoosePic(image);
  168.       value:=GetPixel(h,v);
  169.       ChoosePic(dump);
  170.       write(value:4);
  171.     end;
  172.     writeln;
  173.   end;
  174.   ChoosePic(image);
  175. end;
  176.  
  177.  
  178. macro 'Resize All';
  179. {
  180. Resizes and/or rotates all currently open widows. For example,
  181. change the  ScaleAndRotate command below to
  182. ScaleAndRotate(2,2,0)  to change the size of all the images
  183. in a movie loop sequence from 128 x 128 to 256 x 256.
  184. }
  185. var
  186.   i:integer;
  187. begin
  188.   SetScaling('Bilinear; Create New Window');
  189.   for i:=1 to nPics do begin
  190.     ChoosePic(1);
  191.     ScaleAndRotate(1.9,1.9,0);
  192.     ChoosePic(1);
  193.     Close;
  194.   end;
  195.   for i:=1 to nPics do begin
  196.     ChoosePic(i);
  197.     SetPicName(i);
  198.   end;
  199. end;
  200.  
  201.  
  202. macro 'Dispose All';
  203. begin
  204.   DisposeAll;
  205. end;
  206.  
  207.  
  208. macro 'Save All';
  209. {
  210. Saves all currently open images in a folder using '0001', '0002', etc.
  211. as the file names. The save file dialog box will be displayed once
  212. so that you can specify the folder to save the files in.
  213. }
  214. var
  215.   n:integer;
  216. begin
  217.   for n:=1 to nPics do begin
  218.     SelectPic(n);
  219.     SetPicName(n:2);
  220.     SaveAs;
  221.     {Export;}
  222.   end;
  223. end;
  224.  
  225.  
  226. macro 'Make Movie to Disk';
  227. {
  228. }
  229. var
  230.   nFrames,n,Left,Top,Width,Height:integer;
  231.   Delay:real;
  232.   isRoi:boolean;
  233. begin
  234.   GetRoi(Left,Top,Width,Height);
  235.   isRoi:=width>0;
  236.   nFrames:=GetNumber('Number of Frames?',10);
  237.   delay:=GetNumber('Delay Between Frames(seconds)?',60);
  238.   for n:=1 to nFrames do begin
  239.     Capture;
  240.     if isRoi then MakeRoi(Left,Top,Width,Height);
  241.     SetPicName('Frame ',n);
  242.     SaveAs;
  243.     Wait(delay);
  244.   end;
  245. end;
  246.  
  247.  
  248. macro 'Import FITS';
  249. {
  250. This is an example of how to decode an image file header. In this case, the header is 2880 bytes long and bytes 266-269 contain the width(ASCII) and bytes
  251. 246-249 cantain the height. Refer to "FITS:A Flexible Image Transport System",
  252. Astronomy and Astrophysics Supplement Series 44, 1981, 363-370.
  253. }
  254. var
  255.   width,height,offset,i,d,m:integer;
  256. begin
  257.   width:=512; 
  258.   height:=1;
  259.   offset:=0;
  260.   SetImport('8-bit'); 
  261.   SetCustom(width,height,offset);
  262.   Import(''); {Read in header as an image, prompting for the file name.}
  263.   if not ((GetPixel(108,0)=49) and (GetPixel(109,0)=54)) then begin
  264.     {BITPIX<>16}
  265.     PutMessage('This macro only reads 16-bit FITS files');
  266.     Dispose(nPics);
  267.     exit;
  268.   end;
  269.   m:=1000;
  270.   width:=0;
  271.   for i:=266 to 269 do begin
  272.     d:=GetPixel(i,0);
  273.     if d=32 then d:=48;
  274.     d:=d-48;
  275.     width:=width+d*m;
  276.     m:=m/10;
  277.   end;
  278.   m:=1000;
  279.   height:=0;
  280.   for i:=346 to 349 do begin
  281.     d:=GetPixel(i,0);
  282.     if d=32 then d:=48;
  283.     d:=d-48;
  284.     height:=height+d*m;
  285.     m:=m/10;
  286.   end;
  287.   Dispose(nPics);  {The ID of the last window opened is equal to nPics.}
  288.   offset:=2880;
  289.   SetImport('16-bit Signed; Calibrate; Autoscale');
  290.   SetCustom(width,height,offset);
  291.   Import('');  {No prompt this time; Import remembers the name.}
  292.   FlipVertical;
  293. end;
  294.  
  295.  
  296. macro 'Average two Images';
  297.   {Generates the arithmetic average of two images.}
  298. begin
  299.   if nPics<>2 then begin
  300.     PutMessage('This macro requires exactly two image windows to be open.');
  301.     Exit;
  302.   End;
  303.   ScaleMath(false);
  304.   MultiplyByConstant(0.5);
  305.   NextWindow;
  306.   MultiplyByConstant(0.5);
  307.   SelectAll;
  308.   Copy;
  309.   NextWindow;
  310.   Paste;
  311.   Add;
  312. end;
  313.  
  314.  
  315. macro 'Make Montage [M]';
  316. {Opens a new window and creates in it a composite image made from all}
  317. {currently open images. All the images must be the same size.}
  318. var
  319.   width,height,w,h,mWidth,mHeight,nWindows,left,top:integer;
  320.   RoiWidth,RoiHeight,RoiWidth,RoiHeight,i,hloc,vloc:integer;
  321.   montage,temp:integer;
  322.   scale:real;
  323.   SameSize:boolean;
  324. begin
  325.   nWindows:=nPics;
  326.   SameSize:=true;
  327.   GetPicSize(width,height);
  328.   for i:=1 to nPics do begin
  329.     SelectPic(i);
  330.     GetPicSize(w,h);
  331.     SameSize:=SameSize and (w=width) and (h=height);
  332.   end;
  333.   if (nWindows<2) or not SameSize then begin
  334.     PutMessage('This macro needs two or more images of the same size in order to create a montage.');
  335.     Exit;
  336.   end;
  337.   SetBackground(0);
  338.   MakeNewWindow('Montage');
  339.   montage:=nWindows+1;
  340.   GetPicSize(mWidth,mHeight);
  341.   SelectPic(1);
  342.   Duplicate('Temp');
  343.   temp:=nWindows+2;
  344.   scale:=GetNumber('Scaling Factor:',0.25);
  345.   hloc:=-(RoiWidth);
  346.   vloc:=0;
  347.   for i:=1 to nWindows do begin
  348.     SelectPic(i);
  349.     SelectAll;
  350.     copy;
  351.     SelectPic(temp);
  352.     paste;
  353.     SelectAll;
  354.     ScaleSelection(scale,scale);
  355.     RestoreRoi;
  356.     if i=1 then begin
  357.       GetRoi(left,top,RoiWidth,RoiHeight);
  358.       hloc:=-RoiWidth;
  359.       vloc:=0;
  360.     end;
  361.     Copy;
  362.     SelectPic(montage);
  363.     hloc:=hloc+RoiWidth;
  364.     if (hloc+RoiWidth)>mWidth then begin
  365.       hloc:=0;
  366.       vloc:=vloc+RoiHeight;
  367.     end;
  368.     MakeRoi(hloc,vloc,RoiWidth,RoiHeight);
  369.     Paste;
  370.   end;
  371.   KillRoi;
  372.   SelectPic(temp);
  373.   Dispose;
  374. end;
  375.  
  376.  
  377. macro 'Make Sine Wave';
  378. var
  379.   left,top,width,height,i:integer;
  380.   ppp,scale:real;
  381. begin
  382.   MakeNewWindow('Sine Wave');
  383.   SelectAll;
  384.   GetRoi(left,top,Width,Height);
  385.   if width=0 then begin
  386.     PutMessage('This macro requires a rectangular selection.');
  387.     Exit;
  388.   end;
  389.   ppp:=GetNumber('Pixels per period',100);
  390.   Scale:=ppp/6.28;
  391.   MakeRoi(left,top,1,height);
  392.   for i:=1 to width do begin
  393.     SetForeground(sin(i/scale)*127 +128);
  394.     {SetForeground((sin(i/scale)*127 +128)*(i+30)/(width));}
  395.     fill;
  396.     MoveRoi(1,0);
  397.   end;
  398.   KillRoi;;
  399. end;`
  400.  
  401.  
  402. macro 'Grid';
  403. var
  404.   n,PicWidth,PicHeight,hloc,vloc,size:integer;
  405. begin
  406.   n:=24;
  407.   GetPicSize(PicWidth,PicHeight);
  408.   if PicWidth=0 then begin
  409.     PutMessage
  410.     ('This macro needs an opened image, preferably in color, to operate on.');
  411.     Exit;
  412.   end;
  413.   size:=round(PicWidth/n);
  414.   repeat
  415.     hloc:=((PicWidth*random) div size)*size;
  416.     vloc:=((PicHeight*random) div size)*size;
  417.     MakeRoi(hloc,vloc,size,size);
  418.     SetForeground(255*random);
  419.     fill;
  420.     {Invert;}
  421.   until Button;
  422.   KillRoi;
  423. end;
  424.  
  425.  
  426. macro 'Camera and Light Source Test';
  427.   {Use to test cameras and light sources for temporal stability.}
  428. var
  429.   delay,nFrames:integer;
  430.   i:real;
  431. begin
  432.    nFrames:=trunc(GetNumber('Number of Frames:',10));
  433.    delay:=trunc(GetNumber('Delay in seconds:',10));
  434.    for I:=1 to nFrames do begin
  435.      Capture;
  436.      Measure;
  437.      wait(delay);
  438.   end;
  439. end;
  440.  
  441.  
  442. macro 'Plot XYZ';
  443. {
  444. Plots X-Y coordinate points with an optional intensity(Z). Values are read from
  445. a 2 or 3 column tab-delimited text file. Data must be scaled as follows:
  446. 0<=X<width; 0<=Y<height; 0<=Z<=255.
  447. }
  448. var
  449.   width,height:integer;
  450. begin
  451.   width:=450;
  452.   height:=500;
  453.   SetNewSize(width,height);
  454.   MakeNewWindow('Plot');
  455.   PlotXYZ;
  456. end;
  457.  
  458.  
  459. macro '5x5 [5]';
  460. {
  461. Note: you only see the open file dialog box the first time one of
  462. these macros is called, since Image keeps track of the folder
  463. containing the convolution kernels. Use Record Preferences
  464. to permanently record the pointers to this folder.
  465. }
  466. begin
  467.   convolve('Hat(5x5)');
  468. end;
  469.  
  470. macro '7x7  [7]'
  471. begin
  472.   convolve('Hat(7x7)');
  473. end;
  474.  
  475. macro '9x9  [9]'
  476. begin
  477.   convolve('Hat(9x9)');
  478. end;
  479.  
  480.